package com.rxjava.test.now;

import java.net.URI;
import java.util.List;

public class ApiWrapper {
    Api api;

    public AsynJob<List<Cat>> queryCats(String query) {
        return new AsynJob<List<Cat>>() {

            @Override
            public void start(Callback<List<Cat>> callback) {
                api.queryCats(query, new Api.CatsQueryCallback() {
                    @Override
                    public void onCatListReceived(List<Cat> cats) {
                        callback.onResule(cats);
                    }

                    @Override
                    public void onError(Exception e) {
                        callback.onError(e);
                    }
                });
            }
        };

    }

    public AsynJob<URI> store(Cat cat) {
        return new AsynJob<URI>() {
            @Override
            public void start(Callback<URI> callback) {
                api.store(cat, new Api.StoreCallback() {
                    @Override
                    public void onCatStored(URI uri) {
                        callback.onResule(uri);
                    }

                    @Override
                    public void onStoreFailed(Exception e) {
                        callback.onError(e);
                    }
                });
            }
        };
    }
}
